package com.westa.smallshop;

import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.widget.ImageView;

import com.alibaba.fastjson.JSONObject;
import com.bumptech.glide.Glide;
import com.westa.smallshop.login.LoginActivity;
import com.westa.smallshop.shop.ShopActivity;
import com.westa.smallshop.util.UserSPUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

public class SplashActivity extends AppCompatActivity {

    @BindView(R.id.iv_splash)
    ImageView mIvSplash;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        ButterKnife.bind(this);

        initSplashImage();
        initServerConfig();
    }

    private void initServerConfig() {

    }

    private void initSplashImage() {

        Glide.with(this)
                .load(R.drawable.img_splash)
                .centerCrop()
                .into(mIvSplash);
        startNextActivity();

//        if (!TextUtils.isEmpty(UserSPUtils.getStartPageImg(getApplicationContext()))) {
//
//            Glide.with(this)
//                    .load(MyHttpClient.IMAGE_PATH_PR + UserSPUtils.getStartPageImg(getApplicationContext()))
//                    .diskCacheStrategy(DiskCacheStrategy.ALL)
//                    .centerCrop()
//                    .into(mIvSplash);
//        }
    }

    private void saveConfig(JSONObject object) {

    }

    private void startNextActivity() {

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {

                if (!TextUtils.isEmpty(UserSPUtils.getAccount(getApplicationContext()))) {
                    ShopActivity.startActivity(SplashActivity.this);
                } else {
                    LoginActivity.startActivity(SplashActivity.this);
                }
                finish();
            }
        }, 2000);
    }
}
